package com.kang.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.kang.dao.ItemDetailMapper;
import com.kang.pojo.ItemDetail;
import com.kang.service.ItemDetailService;

/**
 * 物品批次服务层实现类
 * 
 * @author zs614
 *
 */
@Service
public class ItemDetailServiceImpl implements ItemDetailService {
	/**
	 * 物品批次持久层
	 */
	@Resource
	private ItemDetailMapper idm;

	/**
	 * 添加物品批次
	 * 
	 * @param itemDetail
	 *            物品批次实体类
	 * @return
	 */
	@Override
	public int addItemDetail(ItemDetail itemDetail) {
		return idm.addItemDetail(itemDetail);
	}

	/**
	 * 生成批次号
	 * 
	 * @return
	 */
	@Override
	public String generateBatchNumber() {

		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		String text = sdf.format(new Date()) + "0001";
		Long no = Long.parseLong(text);
		String max = idm.generateBatchNumber();
		Long l = 0l;
		if (max != null) {
			l = Long.parseLong(max.replaceAll("[a-zA-Z]", ""));
		}
		if (l >= no) {
			no = l + 1;
		}
		return "" + no;

	}

	/**
	 * 根据条件查询出物品批次
	 * 
	 * @param itemDetail
	 *            物品批次实体类
	 * @return
	 */
	@Override
	public ItemDetail selectItemDetailByCondition(ItemDetail itemDetail) {
		return idm.selectItemDetailByCondition(itemDetail);
	}

}
